package com.tjmc.tiomsresource.parser;

import com.tjmc.tiomscore.model.TranPtnHwNel;
import org.dom4j.Element;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Luc
 * @version 1.0
 * @date 2020-05-11 17:56
 */

@Component("cmNelParser")
public class CMNelParser extends AbstractParser<TranPtnHwNel> {

    public List<TranPtnHwNel> parseXML(List<Element> objectElements) {
        if(null == objectElements || objectElements.size() == 0) {
            return null;
        }
        List<TranPtnHwNel> tranPtnHwNelList = new ArrayList<>();
        int j = 0;
        for(Element objectElement : objectElements) {
            if(++j == PRINT_LOG_SPLIT || j == objectElements.size()) {
                logger.info("解析：" + j + ", size=" + objectElements.size());
            }
            String rmUID = objectElement.attributeValue("rmUID");
            TranPtnHwNel tranPtnHwNel = new TranPtnHwNel();
            tranPtnHwNel.setRmuid(rmUID);
            List<Element> vElements = objectElement.elements("V");
            if(null == vElements || vElements.size() == 0) {
                continue;
            }
            for(Element vElement : vElements) {
                int i = Integer.parseInt(vElement.attributeValue("i"));
                switch(i) {
                    case 1:
                        tranPtnHwNel.setNativename(vElement.getTextTrim());
                        break;
                    case 2:
                        tranPtnHwNel.setLocation(vElement.getTextTrim());
                        break;
                    case 3:
                        tranPtnHwNel.setProductname(vElement.getTextTrim());
                        break;
                    case 4:
                        tranPtnHwNel.setVendor(vElement.getTextTrim());
                        break;
                    case 5:
                        tranPtnHwNel.setReality(vElement.getTextTrim());
                        break;
                    case 6:
                        tranPtnHwNel.setIpaddress(vElement.getTextTrim());
                        break;
                    case 7:
                        tranPtnHwNel.setControlplaneip(vElement.getTextTrim());
                        break;
                    case 8:
                        tranPtnHwNel.setHardwareversion(vElement.getTextTrim());
                        break;
                    case 9:
                        tranPtnHwNel.setSoftwareversion(vElement.getTextTrim());
                        break;
                    case 10:
                        tranPtnHwNel.setMaxcapacity(vElement.getTextTrim());
                        break;
                    case 11:
                        tranPtnHwNel.setState(vElement.getTextTrim());
                        break;
                }
            }
            tranPtnHwNelList.add(tranPtnHwNel);
        }
        return tranPtnHwNelList.size()==0?null:tranPtnHwNelList;
    }
}
